<!-- 工单指派 -->

<template>
  <div>
    <FormSlot bind="assignUserId" :tip="tip" noLabel required>
      <ChooseUserOne :obj="one" bind="user" :organId="one.user.organId[0]" repair @change="toChange" />
    </FormSlot>

    <FormTextarea v-if="isForward" label="转派意见" bind="opinion" :max="100" required />
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyAssign',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb('deal')],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 是否为转派
     */
    isForward() {
      const { method } = this.one
      return method === 'forward'
    },

    /**
     * 提示
     */
    tip() {
      const { isForward } = this
      return isForward ? '请选择转派人' : '请选择指派人'
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 点击复选
     */
    toChange({ uaaUserId, name, phone, organId }) {
      CORE.merge(this.one, {
        assignUserId: uaaUserId,
        assignUserName: name,
        assignUserPhone: phone,
        user: { uaaUserId, name, phone, organId: [organId[0]] }, // 指派人
      })
    },
  },
}
</script>
